<?php
declare (strict_types = 1);

namespace app\middleware;

class ApiCheck
{
    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {
        $token = $request->header('token');
        if ($token){
           $res =  checkToken($token);
           if ($res['code'] == 1){
               $uid = $res['data']->uid;
               $request->uid = $uid;
           }else{
               return  json(['code'=>300,'msg'=>'token错误']);
           }
        }else{
            return  json(['code'=>300,'msg'=>'请登录']);
        }
        return $next($request);
    }
}
